﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using YJKRoomInspection.Model;
using YJKRoomInspection.Properties;
using YArchitech.Revit;
using YJKRevitFamilyDataBase;
using YJKGeometryFuncs;
using YJKInspectModelFunc;
using YJKInspectModelFunc.ControlLayer;
using YJKInspectModelFunc.ModelLayer;

namespace YJKRoomInspection.Utiltiy
{
	public static class Utility
	{
		public static bool JudgeStairRoomByArea(Autodesk.Revit.DB.Document m_doc, BaseRoomPacker tmpPacker)
		{
			List<BaseHostInRoomPacker> list = new List<BaseHostInRoomPacker>();
			List<Stairs> list2 = new List<Stairs>();
			new List<List<StairsRun>>();
			new List<List<Curve>>();
			new List<lstCurvePtAndArea>();
			double num = 0.0;
			foreach (KeyValuePair<BaseHostInRoomPacker, XYZ> keyValuePair in tmpPacker.LstHostElementPacker)
			{
				list.Add(keyValuePair.Key);
			}
			foreach (BaseHostInRoomPacker baseHostInRoomPacker in list)
			{
				if (baseHostInRoomPacker.ThisElement is Stairs)
				{
					list2.Add(baseHostInRoomPacker.ThisElement as Stairs);
				}
			}
			foreach (Stairs tmpStair in list2)
			{
				double num2 = Utility.AddStairArea(Utility.FilterSameCurves(Utility.GetStairCurve(Utility.FindStairRuns(tmpStair))));
				num += num2;
			}
			double area = tmpPacker.ThisRoom.Area;
			return num / area >= 0.16666666666666666;
		}

		public static bool JudgeDoorOrWinIsRight(FamilyInstance tmpDoor)
		{
			string input = string.Empty;
			string value = string.Empty;
			string input2 = string.Empty;
			string input3 = string.Empty;
			bool result;
			try
			{
				ElementId typeId = tmpDoor.GetTypeId();
				FamilySymbol familySymbol = RevitVersionFuncs.GetElement(tmpDoor.Document, typeId) as FamilySymbol;
				input3 = familySymbol.Name;
				string name = tmpDoor.Symbol.Family.Name;
				string name2 = tmpDoor.Symbol.Name;
				if (!Utility.IsValidDoorWinClassAFamilyName(name, name2))
				{
					result = false;
				}
				else
				{
					if (familySymbol != null)
					{
						Parameter parameter = familySymbol.GetParameter("类型标记");
						if (parameter != null && parameter.HasValue)
						{
							input = parameter.AsString();
						}
						Parameter parameter2 = familySymbol.GetParameter("防火等级");
						if (parameter2 != null && parameter2.HasValue)
						{
							value = parameter2.AsString();
						}
						Parameter parameter3 = familySymbol.GetParameter("类型名称");
						if (parameter3 != null && parameter3.HasValue)
						{
							input2 = parameter3.AsString();
						}
					}
					bool flag = false;
					if (Regex.IsMatch(input2, Resources.Str_FireDoorNameOne) || Regex.IsMatch(input3, Resources.Str_FireDoorNameOne) || Regex.IsMatch(input, Resources.Str_FireDoorNameOne) || StaticRescource.m_FireLevel.Contains(value))
					{
						flag = true;
					}
					else if (Regex.IsMatch(input2, Resources.Str_FireDoorNameTwo) || Regex.IsMatch(input3, Resources.Str_FireDoorNameTwo) || Regex.IsMatch(input, Resources.Str_FireDoorNameTwo) || StaticRescource.m_FireLevel.Contains(value))
					{
						flag = true;
					}
					else if (Regex.IsMatch(input2, Resources.Str_FireDoorNameThree) || Regex.IsMatch(input3, Resources.Str_FireDoorNameThree) || Regex.IsMatch(input, Resources.Str_FireDoorNameThree) || StaticRescource.m_FireLevel.Contains(value))
					{
						flag = true;
					}
					result = flag;
				}
			}
			catch (Exception)
			{
				result = false;
			}
			return result;
		}

		public static bool JudgeDoorIsRight(FamilyInstance tmpDoor)
		{
			string input = null;
			string value = null;
			string input2 = null;
			if (tmpDoor == null)
			{
				return false;
			}
			bool result;
			try
			{
				ElementId typeId = tmpDoor.GetTypeId();
				FamilySymbol familySymbol = RevitVersionFuncs.GetElement(tmpDoor.Document, typeId) as FamilySymbol;
				string name = familySymbol.Name;
				if (familySymbol != null)
				{
					Parameter parameter = familySymbol.GetParameter("类型标记");
					if (parameter != null && parameter.HasValue)
					{
						input = parameter.AsString();
					}
					Parameter parameter2 = familySymbol.GetParameter("防火等级");
					if (parameter2 != null && parameter2.HasValue)
					{
						value = parameter2.AsString();
					}
					Parameter parameter3 = familySymbol.GetParameter("类型名称");
					if (parameter3 != null && parameter3.HasValue)
					{
						input2 = parameter3.AsString();
					}
				}
				bool flag = false;
				if (Regex.IsMatch(input2, Resources.Str_FireDoorNameOne) || Regex.IsMatch(name, Resources.Str_FireDoorNameOne) || Regex.IsMatch(input, Resources.Str_FireDoorNameOne) || StaticRescource.m_FireLevel.Contains(value))
				{
					flag = true;
				}
				else if (Regex.IsMatch(input2, Resources.Str_FireDoorNameTwo) || Regex.IsMatch(name, Resources.Str_FireDoorNameTwo) || Regex.IsMatch(input, Resources.Str_FireDoorNameTwo) || StaticRescource.m_FireLevel.Contains(value))
				{
					flag = true;
				}
				else if (Regex.IsMatch(input2, Resources.Str_FireDoorNameThree) || Regex.IsMatch(name, Resources.Str_FireDoorNameThree) || Regex.IsMatch(input, Resources.Str_FireDoorNameThree) || StaticRescource.m_FireLevel.Contains(value))
				{
					flag = true;
				}
				result = flag;
			}
			catch (Exception)
			{
				result = false;
			}
			return result;
		}

		public static double AddStairArea(List<lstCurvePtAndArea> lstptAndArea)
		{
			double num = 0.0;
			foreach (lstCurvePtAndArea lstCurvePtAndArea in lstptAndArea)
			{
				num += lstCurvePtAndArea.CurveArea;
			}
			return num;
		}

		public static double ChangeAreaByUnit(double tmpArea)
		{
			tmpArea = tmpArea * 304.8 * 304.8 / 1000.0 / 1000.0;
			return tmpArea;
		}

		public static List<lstCurvePtAndArea> FilterSameCurves(List<List<Curve>> tmplstCurve)
		{
			List<List<Curve>> list = new List<List<Curve>>();
			List<lstCurvePtAndArea> list2 = new List<lstCurvePtAndArea>();
			for (int i = 0; i < tmplstCurve.Count; i++)
			{
				List<Curve> list3 = new List<Curve>();
				for (int j = 0; j < tmplstCurve[i].Count; j++)
				{
                    Curve item = YJKInspectModelFunc.Utility.TransformCurveAtZAixs(tmplstCurve[i][j], 0.0, true);
					list3.Add(item);
				}
				list.Add(list3);
			}
			for (int k = 0; k < list.Count; k++)
			{
				lstCurvePtAndArea lstCurvePtAndArea = new lstCurvePtAndArea();
                XYZ centerPt = YJKInspectModelFunc.Utility.CalculateLstCurveMidPoint(list[k]);
				double curveArea = Geometry.AoArea(list[k]);
				lstCurvePtAndArea.CenterPt = centerPt;
				lstCurvePtAndArea.CurveArea = curveArea;
				list2.Add(lstCurvePtAndArea);
			}
			return Utility.RemoveSamelstCurve(list2);
		}

		public static Level GetFilledRegionLevel(FilledRegion tmpObj, List<Level> lstLevel, Autodesk.Revit.DB.View view)
		{
			double num = 0.0;
			Level result = null;
			Options options = new Options();
			options.ComputeReferences = true;
			options.IncludeNonVisibleObjects = true;
			if (view != null)
			{
				options.View = view;
			}
			else
			{
				options.DetailLevel = (ViewDetailLevel)3;
			}
			List<GeometryObject> geometryObjectArray = RevitVersionFuncs.GetGeometryObjectArray(tmpObj.get_Geometry(options));
			int i = 0;
			while (i < geometryObjectArray.Count)
			{
				GeometryObject geometryObject = geometryObjectArray[i];
				if (!(geometryObject is Solid))
				{
					break;
				}
				IEnumerator enumerator = (geometryObject as Solid).Edges.GetEnumerator();
				{
					if (!enumerator.MoveNext())
					{
						break;
					}
					num = ((Edge)enumerator.Current).AsCurve().GetEndPoint(0).Z;
					break;
				}
			}
			foreach (Level level in lstLevel)
			{
				if (level.Elevation == num)
				{
					result = level;
					break;
				}
			}
			return result;
		}

		public static List<lstCurvePtAndArea> RemoveSamelstCurve(List<lstCurvePtAndArea> lstptAndArea)
		{
			if (lstptAndArea.Count == 1)
			{
				return lstptAndArea;
			}
			for (int i = 0; i < lstptAndArea.Count; i++)
			{
				for (int j = i + 1; j < lstptAndArea.Count; j++)
				{
					if (lstptAndArea[i].CenterPt.IsAlmostEqualTo(lstptAndArea[j].CenterPt) && Geometry.IsEqual(lstptAndArea[i].CurveArea, lstptAndArea[j].CurveArea))
					{
						lstptAndArea.Remove(lstptAndArea[j]);
						j--;
					}
				}
			}
			return lstptAndArea;
		}

		public static List<List<Curve>> GetStairCurve(List<List<StairsRun>> lstStairRun)
		{
			List<List<Curve>> list = new List<List<Curve>>();
			for (int i = 0; i < lstStairRun.Count; i++)
			{
				foreach (StairsRun stairsRun in lstStairRun[i])
				{
					List<Curve> list2 = new List<Curve>();
					foreach (GeometryObject geometryObject in stairsRun.GetFootprintBoundary())
					{
						if (geometryObject is Curve)
						{
							list2.Add(geometryObject as Curve);
						}
					}
					list.Add(list2);
				}
			}
			return list;
		}

		public static List<List<StairsRun>> FindStairRuns(Stairs tmpStair)
		{
			List<StairsRun> list = new List<StairsRun>();
			List<List<StairsRun>> list2 = new List<List<StairsRun>>();
			List<List<ElementId>> list3 = new List<List<ElementId>>();
			List<ElementId> item = tmpStair.GetStairsRuns().ToList<ElementId>();
			list3.Add(item);
			for (int i = 0; i < list3.Count; i++)
			{
				foreach (ElementId elementId in list3[i])
				{
					StairsRun stairsRun = tmpStair.Document.GetElement(elementId) as StairsRun;
					if (stairsRun != null)
					{
						stairsRun.BeginsWithRiser = true;
						stairsRun.EndsWithRiser = true;
					}
					list.Add(stairsRun);
				}
				list2.Add(list);
			}
			return list2;
		}

		public static List<int> GetNotDeleteRoom(Autodesk.Revit.DB.Document inputDoc)
		{
			List<int> list = new List<int>();
			new InsertData();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(inputDoc);
			List<FrontRoomPacker> list2 = new List<FrontRoomPacker>();
			foreach (Element element in filteredElementCollector.OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements())
			{
				if (ElementPackerManger.NowValueStructure.Count != 0 && ElementPackerManger.NowValueStructure.ContainsKey(-1) && ElementPackerManger.NowValueStructure[-1].ContainsKey(element.Id.IntegerValue) && ElementPackerManger.NowValueStructure[-1][element.Id.IntegerValue] is FrontRoomPacker && ElementPackerManger.NowValueStructure[-1][element.Id.IntegerValue] is FrontRoomPacker)
				{
					list2.Add(ElementPackerManger.NowValueStructure[-1][element.Id.IntegerValue] as FrontRoomPacker);
				}
			}
			foreach (FrontRoomPacker frontRoomPacker in list2)
			{
				if (InsertDataToRoom.ReadFromElement<InsertData>(frontRoomPacker.ThisRoom, Resources.GUID).FrontRoomType != null || !frontRoomPacker.IfAdded || frontRoomPacker.LstHostElementPacker.Count != 0)
				{
					list.Add(frontRoomPacker.ThisElement.Id.IntegerValue);
				}
			}
			return list;
		}

		public static string SubstringRoomName(string tmpName)
		{
			char[] array = new char[tmpName.Length];
			array = tmpName.ToCharArray();
			for (int i = 0; i < array.Count<char>(); i++)
			{
				if (array[i] == ' ')
				{
					tmpName = tmpName.Substring(0, i);
					break;
				}
			}
			return tmpName;
		}

		public static Dictionary<BaseDoorPacker, Room> GetOutDoorNum(BaseAreaPacker tmpAreaPacker)
		{
			List<BaseDoorPacker> list = new List<BaseDoorPacker>();
			Dictionary<BaseDoorPacker, Room> dictionary = new Dictionary<BaseDoorPacker, Room>();
			new List<List<BaseDoorPacker>>();
			foreach (BaseDoorPacker baseDoorPacker in tmpAreaPacker.LstDoorPackerInThis)
			{
                if (baseDoorPacker.LstConctRooms.Count == 1 && YJKInspectModelFunc.Utility.IfDoorIsOutSideDoor(baseDoorPacker))
				{
					list.Add(baseDoorPacker);
				}
			}
            List<List<BaseDoorPacker>> list2 = YJKInspectModelFunc.Utility.GroupDoorsByDistance(list, Utility.mToFeet(StaticRescource.m_OutDoorVal), Resources.Str_PushDoor);
			List<BaseDoorPacker> list3 = new List<BaseDoorPacker>();
			foreach (List<BaseDoorPacker> collection in list2)
			{
				list3.AddRange(collection);
			}
			foreach (BaseDoorPacker baseDoorPacker2 in list3)
			{
				if (baseDoorPacker2.LstConctRooms.Count == 1 && !dictionary.Keys.Contains(baseDoorPacker2))
				{
					dictionary.Add(baseDoorPacker2, baseDoorPacker2.LstConctRooms[0].ThisRoom);
				}
			}
			return dictionary;
		}

		public static Dictionary<BaseDoorPacker, Room> GetFrontRoomAndStairDoor(BaseAreaPacker tmpAreaPacker)
		{
			List<BaseDoorPacker> list = new List<BaseDoorPacker>();
			list.AddRange(tmpAreaPacker.LstDoorPackerInThis);
			Dictionary<BaseDoorPacker, Room> dictionary = new Dictionary<BaseDoorPacker, Room>();
			List<BaseRoomPacker> list2 = new List<BaseRoomPacker>();
			InsertData insertData = new InsertData();
			for (int i = 0; i < list.Count; i++)
			{
				list2.AddRange(list[i].LstConctRooms);
				foreach (BaseRoomPacker baseRoomPacker in list2)
				{
					if (i < 0)
					{
						break;
					}
					if (baseRoomPacker.LstBaseDoorPacker.Count == 1 && baseRoomPacker.LstHostElementPacker.Count == 0)
					{
						list.Remove(list[i]);
						i--;
					}
				}
				list2.Clear();
			}
			foreach (BaseDoorPacker baseDoorPacker in list)
			{
				if (baseDoorPacker.LstConctRooms.Count > 1)
				{
					foreach (BaseRoomPacker baseRoomPacker2 in baseDoorPacker.LstConctRooms)
					{
						insertData = InsertDataToRoom.ReadFromElement<InsertData>(baseRoomPacker2.ThisRoom, Resources.GUID);
						if (baseRoomPacker2.LstHostElementPacker.Count >= 1 && Utility.JudgeStairRoomByArea(baseRoomPacker2.UseDocument, baseRoomPacker2 as FrontRoomPacker))
						{
							if (!dictionary.Keys.Contains(baseDoorPacker))
							{
								dictionary.Add(baseDoorPacker, baseRoomPacker2.ThisRoom);
							}
							else if (Utility.IfRoomIsFrontRoom(dictionary[baseDoorPacker]).FrontRoomType != null)
							{
								dictionary[baseDoorPacker] = baseRoomPacker2.ThisRoom;
							}
						}
						else if (insertData.FrontRoomType != null && !dictionary.Keys.Contains(baseDoorPacker))
						{
							dictionary.Add(baseDoorPacker, baseRoomPacker2.ThisRoom);
						}
					}
				}
			}
			return dictionary;
		}

		public static InsertData IfRoomIsFrontRoom(Room input)
		{
			InsertData insertData = new InsertData();
			try
			{
				insertData = InsertDataToRoom.ReadFromElement<InsertData>(input, Resources.GUID);
				if (insertData != null)
				{
					return insertData;
				}
			}
			catch (Exception)
			{
			}
			return null;
		}

		public static List<Element> FilterElementFormDoc(UIDocument inputUiDoc, List<Level> lstUseLevel)
		{
			Document document = inputUiDoc.Document;
			InsertData insertData = new InsertData();
			string guid = Resources.GUID;
			List<Element> list = new List<Element>();
			List<Element> list2 = new List<Element>();
			List<Element> list3 = new List<Element>();
			List<int> list4 = new List<int>();
			IList<Element> collection = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements();
			IList<Element> collection2 = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_DetailComponents).WhereElementIsNotElementType().ToElements();
			list.AddRange(collection);
			list.AddRange(collection2);
			foreach (Level level in lstUseLevel)
			{
				list4.Add(level.Id.IntegerValue);
			}
			foreach (Element element in list)
			{
				insertData = InsertDataToRoom.ReadFromElement<InsertData>(element, guid);
				if (element is Room && insertData.FrontRoomType != null && (element as Room).Area != 0.0)
				{
					list2.Add(element);
				}
				else if (element is FilledRegion && insertData.FrontRoomType != null && element.get_Parameter(BuiltInParameter.HOST_AREA_COMPUTED) != null && element.get_Parameter(BuiltInParameter.HOST_AREA_COMPUTED).AsDouble() != 0.0)
				{
					list2.Add(element);
				}
			}
			foreach (Element element2 in list2)
			{
				if (element2 is Room && list4.Contains(element2.LevelId.IntegerValue))
				{
					list3.Add(element2);
				}
				else if (element2 is FilledRegion)
				{
					Level filledRegionLevel = Utility.GetFilledRegionLevel(element2 as FilledRegion, lstUseLevel, inputUiDoc.ActiveView);
					if (filledRegionLevel != null && list4.Contains(filledRegionLevel.Id.IntegerValue))
					{
						list3.Add(element2);
					}
				}
			}
			return list3;
		}

		public static bool FamilyReplace(FamilyInstance useFamilyinstance, Family useFamily, string inputType, bool ifUseAppendCheck = true)
		{
			FamilySymbol familySymbol = null;
			bool result;
			try
			{
				Document document = useFamilyinstance.Document;
				string nowSymbolName = useFamilyinstance.Symbol.Name;
				familySymbol = useFamily.GetSymbols().FirstOrDefault((FamilySymbol fiSymbol) => fiSymbol.Name == nowSymbolName);
				if (inputType == "OutLine")
				{
					if (nowSymbolName.Contains("乙"))
					{
						nowSymbolName = nowSymbolName.Replace('乙', '甲');
					}
					else if (nowSymbolName.Contains("丙"))
					{
						nowSymbolName = nowSymbolName.Replace('丙', '甲');
					}
					else if (nowSymbolName.Contains("丁"))
					{
						nowSymbolName = nowSymbolName.Replace('丁', '甲');
					}
					else
					{
						nowSymbolName += "甲";
					}
				}
				if (ifUseAppendCheck && !Utility.FamilyReplaceAppendCheck(useFamilyinstance, useFamily))
				{
					result = false;
				}
				else
				{
					if (familySymbol == null || inputType == "OutLine")
					{
						Transaction transaction = new Transaction(document, "DuplicateFiSymbol");
						transaction.Start();
						try
						{
							familySymbol = (useFamily.GetSymbols().FirstOrDefault<FamilySymbol>().Duplicate(nowSymbolName) as FamilySymbol);
							double num = useFamilyinstance.Symbol.GetParameter(BuiltInParameter.FAMILY_HEIGHT_PARAM).AsDouble();
							double num2 = useFamilyinstance.Symbol.GetParameter(BuiltInParameter.CASEWORK_WIDTH).AsDouble();
							familySymbol.GetParameter(BuiltInParameter.FAMILY_HEIGHT_PARAM).Set(num);
							familySymbol.GetParameter(BuiltInParameter.CASEWORK_WIDTH).Set(num2);
							transaction.Commit();
						}
						catch (Exception)
						{
							transaction.RollBack();
						}
					}
					Transaction transaction2 = new Transaction(document, "ReplaceFi");
					transaction2.Start();
					try
					{
						useFamilyinstance.Symbol = familySymbol;
						transaction2.Commit();
					}
					catch
					{
						transaction2.RollBack();
					}
					result = true;
				}
			}
			catch
			{
				result = false;
			}
			return result;
		}

		public static List<BaseDoorPacker> GetDoorsFromCloseCurve(ICloseCurveAnalays tmpPacker)
		{
			bool flag = false;
			List<BaseDoorPacker> list = new List<BaseDoorPacker>();
			list = Utility.GetUseDoorFromAllDoors(tmpPacker.GetAllDoors());
			foreach (BaseDoorPacker baseDoorPacker in list)
			{
				if (Regex.IsMatch(baseDoorPacker.FamilySymboleName, Resources.Str_FireDoorNameOne))
				{
					flag = true;
				}
				else if (Regex.IsMatch(baseDoorPacker.FamilySymboleName, Resources.Str_FireDoorNameTwo))
				{
					flag = true;
				}
				else
				{
					if (!Regex.IsMatch(baseDoorPacker.FamilySymboleName, Resources.Str_FireDoorNameThree))
					{
						flag = false;
						break;
					}
					flag = true;
				}
			}
			if (flag)
			{
				return list;
			}
			return null;
		}

		public static List<BaseDoorPacker> FilterOutWall(ICloseCurveAnalays roomPackers)
		{
			List<BaseDoorPacker> list = new List<BaseDoorPacker>();
			for (int i = 0; i < roomPackers.GetAllDoors().Count; i++)
			{
				list.AddRange(roomPackers.GetAllDoors());
			}
			for (int j = 0; j < list.Count; j++)
			{
				if (list[j].LstConctRooms.Count == 1)
				{
					int count = list.Count;
					list.Remove(list[j]);
					if (list.Count != count - 1)
					{
						throw new ArgumentException();
					}
				}
			}
			return list;
		}

		public static List<BaseDoorPacker> FilterEauipmentDoor(ICloseCurveAnalays roomPackers, List<BaseDoorPacker> m_RoomPackers)
		{
			new List<BaseRoomPacker>();
			List<FrontRoomPacker> list = new List<FrontRoomPacker>();
			foreach (BaseRoomPacker baseRoomPacker in roomPackers.GetNearRooms())
			{
				list.Add(baseRoomPacker as FrontRoomPacker);
			}
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].LstBaseDoorPacker.Count == 1 && list[i].LstHostElementPacker.Count == 0)
				{
					m_RoomPackers.Remove(list[i].thisFrontRoomDoor[0]);
				}
			}
			return m_RoomPackers;
		}

		public static List<BaseDoorPacker> FindStairDoorNum(ICloseCurveAnalays roomPackers, List<BaseDoorPacker> m_RoomPackers)
		{
			new List<BaseRoomPacker>();
			List<FrontRoomPacker> list = new List<FrontRoomPacker>();
			List<BaseDoorPacker> list2 = new List<BaseDoorPacker>();
			foreach (BaseRoomPacker baseRoomPacker in roomPackers.GetNearRooms())
			{
				list.Add(baseRoomPacker as FrontRoomPacker);
			}
			int num = 0;
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].LstBaseDoorPacker.Count >= 1 && list[i].LstHostElementPacker.Count >= 1 && Utility.JudgeStairRoomByArea(list[i].UseDocument, list[i]))
				{
					foreach (FrontRoomDoorPacker item in list[i].thisFrontRoomDoor)
					{
						if (m_RoomPackers.Contains(item))
						{
							num++;
							list2.Add(item);
							m_RoomPackers.Remove(list[i].thisFrontRoomDoor[0]);
						}
					}
				}
			}
			return list2;
		}

		public static List<BaseDoorPacker> FindXTDoor(ICloseCurveAnalays tmpRoomPacker)
		{
			int num = 0;
			List<BaseDoorPacker> list = new List<BaseDoorPacker>();
			if (tmpRoomPacker.GetThisElement().Name.Contains("XT"))
			{
				num = tmpRoomPacker.GetAllDoors().Count;
				using (List<BaseDoorPacker>.Enumerator enumerator = tmpRoomPacker.GetAllDoors().GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						BaseDoorPacker item = enumerator.Current;
						list.Add(item);
					}
					goto IL_D6;
				}
			}
			if (tmpRoomPacker.GetThisElement().Name.Contains("消") && tmpRoomPacker.GetThisElement().Name.Contains("梯"))
			{
				num = tmpRoomPacker.GetAllDoors().Count;
				foreach (BaseDoorPacker item2 in tmpRoomPacker.GetAllDoors())
				{
					list.Add(item2);
				}
			}
			IL_D6:
			foreach (BaseDoorPacker baseDoorPacker in tmpRoomPacker.GetAllDoors())
			{
				Parameter parameter = baseDoorPacker.ThisElement.GetParameter("备注");
				if (baseDoorPacker.FamilyName.Contains("消") && baseDoorPacker.FamilyName.Contains("梯"))
				{
					num++;
					list.Add(baseDoorPacker);
				}
				if (parameter != null && parameter.AsString() == "兼消防电梯")
				{
					num++;
					list.Add(baseDoorPacker);
				}
			}
			return list;
		}

		public static List<BaseDoorPacker> GetUseDoorFromAllDoors(List<BaseDoorPacker> lstDoorsFromCurve)
		{
			List<BaseRoomPacker> list = new List<BaseRoomPacker>();
			for (int i = 0; i < lstDoorsFromCurve.Count; i++)
			{
				if (lstDoorsFromCurve[i].LstConctRooms.Count == 1)
				{
					int count = lstDoorsFromCurve.Count;
					lstDoorsFromCurve.Remove(lstDoorsFromCurve[i]);
					int count2 = lstDoorsFromCurve.Count;
					int num = count - 1;
				}
			}
			for (int j = 0; j < lstDoorsFromCurve.Count; j++)
			{
				list.AddRange(lstDoorsFromCurve[j].LstConctRooms);
				foreach (BaseRoomPacker baseRoomPacker in list)
				{
					if (baseRoomPacker.LstBaseDoorPacker.Count == 1 && baseRoomPacker.LstHostElementPacker.Count == 0)
					{
						lstDoorsFromCurve.Remove(baseRoomPacker.LstBaseDoorPacker[0]);
					}
					if (baseRoomPacker.LstBaseDoorPacker.Count >= 1 && baseRoomPacker.LstHostElementPacker.Count >= 1 && Utility.JudgeStairRoomByArea(baseRoomPacker.UseDocument, baseRoomPacker) && lstDoorsFromCurve.Count > 0)
					{
						lstDoorsFromCurve.Remove(lstDoorsFromCurve[j]);
						j--;
					}
				}
				list.Clear();
			}
			return lstDoorsFromCurve;
		}

		public static bool FlipDoor(Autodesk.Revit.DB.Document inputDoc, List<BaseDoorPacker> lsttmpDoor)
		{
			List<FamilyInstance> list = new List<FamilyInstance>();
			foreach (BaseDoorPacker baseDoorPacker in lsttmpDoor)
			{
				list.Add(baseDoorPacker.ThisDoor);
			}
			bool result = false;
			Transaction transaction = new Transaction(inputDoc, "Filp Door");
			transaction.Start();
			foreach (FamilyInstance familyInstance in list)
			{
				if (familyInstance.CanFlipFacing)
				{
					result = familyInstance.flipFacing();
				}
			}
			transaction.Commit();
			return result;
		}

		public static void ShowFilledRegion(UIDocument inputUiDoc, ICollection<ElementId> tmpObj, List<ViewPlan> lstPlan)
		{
			List<ElementId> list = new List<ElementId>();
			ICollection<ElementId> collection = new List<ElementId>();
			list = (tmpObj as List<ElementId>);
			foreach (ElementId elementId in list)
			{
				if (inputUiDoc.Document.GetElement(elementId) is FilledRegion)
				{
					collection.Add(elementId);
				}
			}
			Transaction transaction = new Transaction(inputUiDoc.Document, "Show FilledRegion");
			transaction.Start();
			inputUiDoc.Document.ActiveView.UnhideElements(collection);
			transaction.Commit();
			Selection selection = inputUiDoc.Selection;
			List<Element> list2 = new List<Element>();
			ElementSet elementSet = new ElementSet();
			Element element = null;
			foreach (ElementId elementId2 in list)
			{
				element = inputUiDoc.Document.GetElement(elementId2);
				list2.Add(element);
				elementSet.Insert(element);
			}
			foreach (ViewPlan viewPlan in lstPlan)
			{
				int integerValue = element.LevelId.IntegerValue;
				if (viewPlan.GenLevel != null && viewPlan.GenLevel.Id.IntegerValue == integerValue)
				{
					inputUiDoc.ActiveView = viewPlan;
					break;
				}
			}
			inputUiDoc.ShowElements(elementSet);
			RevitVersionFuncs.SetSelection(selection, list2);
			inputUiDoc.RefreshActiveView();
		}

		public static void HideFilledRegion(UIDocument inputDoc, ICollection<ElementId> tmpId)
		{
			if (tmpId != null && tmpId.Count != 0)
			{
				Transaction transaction = new Transaction(inputDoc.Document, "Hide FilledRegion");
				transaction.Start();
				inputDoc.ActiveView.HideElements(tmpId);
				transaction.Commit();
			}
		}

		public static string GetAppRootPath()
		{
			string location = Assembly.GetExecutingAssembly().Location;
			int length = location.LastIndexOf("\\");
			string text = location.Substring(0, length);
			length = text.LastIndexOf("\\");
			return text.Substring(0, length);
		}

		public static double mToFeet(double Val)
		{
			return Val * 3.2808399;
		}

		public static Family GetAFamily(Autodesk.Revit.DB.Document m_Doc, string useName, bool ifReplaceWhite = false, string useFamilyLibKindName = null, bool ifUseFamilyLib = true)
		{
			List<Family> list = new FilteredElementCollector(m_Doc).OfClass(typeof(Family)).Cast<Family>().ToList<Family>();
			Family family = null;
			if (string.IsNullOrEmpty(useName) || string.IsNullOrWhiteSpace(useName))
			{
				return family;
			}
			if (ifReplaceWhite)
			{
				family = list.Find((Family Fi) => Fi.Name.Equals(useName));
			}
			else
			{
				family = list.Find((Family Fi) => Utility.IfStringEquqlReplacedWhite(Fi.Name, useName));
			}
			if (family == null && ifUseFamilyLib && !string.IsNullOrWhiteSpace(useFamilyLibKindName) && !string.IsNullOrEmpty(useFamilyLibKindName))
			{
				DbFamily dbFamily = Utility.GetFamilysFromFamilyLid(useFamilyLibKindName).Find((DbFamily e) => e.Name == useName);
				if (dbFamily != null)
				{
					family = dbFamily.Load(m_Doc);
				}
			}
			return family;
		}

		public static bool IfStringEquqlReplacedWhite(string firstString, string secondString)
		{
			return Regex.Replace(firstString, "\\s.*", string.Empty).Equals(Regex.Replace(secondString, "\\s.*", string.Empty));
		}

		public static List<DbFamily> GetFamilysFromFamilyLid(string kindName)
		{
			return FamilyLibDatabase.GetSqliteDB(SubjectType.Architecture, StaticRescource.CmdData.Application.Application.VersionNumber).CategoryTable[kindName].GetAllFamilies(true, CheckType.All);
		}

		public static bool IsValid3HourFireWall(Element elemWall)
		{
			try
			{
				Wall wall = elemWall as Wall;
				if (Regex.IsMatch(wall.WallType.Name, "防火"))
				{
					return Regex.IsMatch(wall.WallType.get_Parameter(BuiltInParameter.DOOR_FIRE_RATING).AsString(), "3小时|3h|3H");
				}
			}
			catch
			{
			}
			return false;
		}

		public static bool IsValidFireDoorWinFamilyName(string strFamilyName)
		{
			return Regex.IsMatch(strFamilyName, "防火|FM|fm|FJM|fjm|FC|fc");
		}

		public static bool IsValidDoorWinClassAFamilyName(string strFamilyName, string strSymbolName)
		{
			return (Utility.IsValidFireDoorWinFamilyName(strFamilyName) && !Regex.IsMatch(strFamilyName, Resources.Str_DoorGrade) && !Regex.IsMatch(strSymbolName, Resources.Str_DoorGrade)) || (Utility.IsValidFireDoorWinFamilyName(strSymbolName) && !Regex.IsMatch(strFamilyName, Resources.Str_DoorGrade) && !Regex.IsMatch(strSymbolName, Resources.Str_DoorGrade));
		}

		public static bool IsValidDoorRollingFamilyName(string strFamilyName)
		{
			return Utility.IsValidFireDoorWinFamilyName(strFamilyName) && Regex.IsMatch(strFamilyName, "卷帘");
		}

		public static bool IsValidFireDoors(FamilyInstance fi)
		{
			string name = fi.Symbol.Family.Name;
			string name2 = fi.Symbol.Name;
			return !Utility.IsValidDoorRollingFamilyName(name) && !Utility.IsValidDoorRollingFamilyName(name2) && Utility.IsValidDoorWinClassAFamilyName(name, name2);
		}

		public static bool IsValidFireDoorRollings(FamilyInstance fi)
		{
			string name = fi.Symbol.Family.Name;
			string name2 = fi.Symbol.Name;
			return (Utility.IsValidDoorRollingFamilyName(name) || Utility.IsValidDoorRollingFamilyName(name2)) && Utility.IsValidFireDoorWinFamilyName(name);
		}

		public static bool IsValidFireWindows(FamilyInstance fi)
		{
			string name = fi.Symbol.Family.Name;
			string name2 = fi.Symbol.Name;
			return Utility.IsValidDoorWinClassAFamilyName(name, name2);
		}

		private static bool FamilyReplaceAppendCheck(FamilyInstance useFamilyinstance, Family useFamily)
		{
			int integerValue = useFamilyinstance.Category.Id.IntegerValue;
			if (integerValue != -2000014 && integerValue != -2000011)
			{
				useFamilyinstance.Symbol.Family.Name.IndexOf(Resources.Str_SpecialStrOfRoolDoor);
			}
			return true;
		}

		public static bool IfSingleDoor(Element inputElement)
		{
			return 1000.0 >= Utility.GetWith(inputElement, true);
		}

		private static double GetWith(Element inputElement, bool ifMM = true)
		{
			double num = inputElement.get_Parameter(BuiltInParameter.CASEWORK_WIDTH).AsDouble();
			if (ifMM)
			{
				num = AssistFunc.feetToMM(num);
			}
			return num;
		}
	}
}
